using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace teavch.Utilities.Electrical.Design.Gui.LineDiagram
{
	public partial class PotheadTerminal : ElectricalSymbol
	{

		private Matrix matrix = null;

		private float _topHandRatio = 1f;
		private float _bottomHandRatio = 1f;
		private float _isolatorGapRatio = 1f;
		private float _isolatorHookRatio = .1f;
		private SymbolOrientation _orientation = SymbolOrientation.Verticle;

		public PotheadTerminal()
		{
			InitializeComponent();
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Top Link Line ration of the top node of the Isolator" )]
		public float TopHandRatio
		{
			get { return this._topHandRatio; }
			set
			{
				this._topHandRatio = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Bottom Link Line ration of the bottom node of the Isolator" )]
		public float BottomHandRatio
		{
			get { return this._bottomHandRatio; }
			set
			{
				this._bottomHandRatio = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the ratio of isolator bar hucks of the Isolator" )]
		public float IsolatorHookRatio
		{
			get { return this._isolatorHookRatio; }
			set
			{
				this._isolatorHookRatio = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Gap ration between isolator bar and nodes of the Isolator" )]
		public float IsolatorGapRatio
		{
			get { return this._isolatorGapRatio; }
			set
			{
				this._isolatorGapRatio = value;
				this.Refresh();
			}
		}

		[Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the element orientation of the Isolator" )]
		public SymbolOrientation Orientation
		{
			get { return this._orientation; }
			set
			{
				this._orientation = value;
				this.Refresh();
			}
		}

		protected override void OnPaint( PaintEventArgs e )
		{
			base.OnPaint( e );
			this.Paint( e );
		}

		protected override void OnResize( EventArgs e )
		{
			base.OnResize( e );
			ResizeNow( e );
		}

		private void ResizeNow( EventArgs ea )
		{
			this.Refresh();
		}

		//private new void Paint( PaintEventArgs pea )
		//{
		//	System.Drawing.Drawing2D.PathGradientBrush _gBrush = null;
		//	System.Drawing.Drawing2D.GraphicsPath _gpath = new System.Drawing.Drawing2D.GraphicsPath();

		//	float c1x1 = 0, c1y1 = 0;
		//	float c2x1 = 0, c2y1 = 0;
		//	float h1x1 = 0, h1y1 = 0;
		//	float h2x1 = 0, h2y1 = 0;
		//	float t1size = 0;
		//	float h1size = 0;

		//	float l1x1 = 0, l1y1 = 0, l1x2 = 0, l1y2 = 0;
		//	float l2x1 = 0, l2y1 = 0, l2x2 = 0, l2y2 = 0;
		//	float l3x1 = 0, l3y1 = 0, l3x2 = 0, l3y2 = 0;

		//	t1size = this.SymbolSize;

		//	l1x1 = t1size / 2;
		//	l1y1 = 0;
		//	l1x2 = l1x1;
		//	l1y2 = t1size * this._topHandRatio;

		//	c1x1 = 0;
		//	c1y1 = l1y2;

		//	c2x1 = 0;
		//	c2y1 = l1y2 + t1size + ( t1size * this._isolatorGapRatio );

		//	l2x1 = l1x1;
		//	l2y1 = c2y1 + t1size;
		//	l2x2 = l2x1;
		//	l2y2 = l2y1 + ( t1size * this._bottomHandRatio );

		//	if ( this.State == SymbolState.Off )
		//	{
		//		l3x1 = c2x1;
		//		l3y1 = c2y1 - ( ( t1size * this._isolatorGapRatio ) / 2 );
		//		l3x2 = t1size;
		//		l3y2 = l3y1;
		//	}
		//	else
		//	{
		//		l3x1 = c2x1;
		//		l3y1 = c2y1 - ( ( t1size * this._isolatorGapRatio ) / 2 );
		//		l3x2 = t1size;
		//		l3y2 = l3y1;
		//	}

		//	h1x1 = l3x1;
		//	h1y1 = l3y1 - ( t1size * this._isolatorHookRatio / 2 );
		//	h1size = ( t1size * this._isolatorHookRatio );
		//	l3x1 += h1size;

		//	h2x1 = l3x2 - ( t1size * this._isolatorHookRatio );
		//	h2y1 = h1y1;
		//	l3x2 -= h1size;

		//	if ( this.Fill == false )
		//	{
		//		_gpath.AddLines
		//		( new PointF[]
		//			{ 
		//				new PointF(){ X=c1x1, Y=c1y1}, 
		//				new PointF(){X=t1size, Y=c1y1}, 
		//				new PointF(){X=t1size, Y=c1y1}, 
		//				new PointF(){X=t1size, Y=c1y1}
		//			}
		//		);
		//		//_gpath.AddArc( c2x1, c2y1, t1size, t1size, 0, 360 );
		//	}
		//	else
		//	{

		//		//_gpath.AddArc( c1x1, c1y1, t1size, t1size, 0, 360 );
		//		//_gBrush = new System.Drawing.Drawing2D.PathGradientBrush( _gpath );
		//		//_gBrush.CenterColor = this.Parent.BackColor;
		//		//_gBrush.SurroundColors = new Color[] { this.State == SymbolState.On ? Color.Red : Color.Red };
		//		//_gBrush.WrapMode = WrapMode.TileFlipY;
		//		//pea.Graphics.FillPath( _gBrush, _gpath );

		//		//_gpath.CloseFigure();
		//		//_gpath.AddArc( c2x1, c2y1, t1size, t1size, 0, 360 );
		//		//_gBrush = new System.Drawing.Drawing2D.PathGradientBrush( _gpath );
		//		//_gBrush.CenterColor = this.Parent.BackColor;
		//		//_gBrush.SurroundColors = new Color[] { this.State == SymbolState.On ? Color.Red : Color.Lime };
		//		//_gBrush.WrapMode = WrapMode.TileFlipY;
		//		//pea.Graphics.FillPath( _gBrush, _gpath );

		//		//_gpath.CloseFigure();
		//		//_gpath.AddArc( h1x1, h1y1, h1size, h1size, 0, 360 );
		//		//_gBrush = new System.Drawing.Drawing2D.PathGradientBrush( _gpath );
		//		//_gBrush.CenterColor = this.Parent.BackColor;
		//		//_gBrush.SurroundColors = new Color[] { this.State == SymbolState.On ? Color.Red : Color.Lime };
		//		//_gBrush.WrapMode = WrapMode.TileFlipY;
		//		//pea.Graphics.FillPath( _gBrush, _gpath );

		//		//_gpath.CloseFigure();
		//		//_gpath.AddArc( h2x1, h2y1, h1size, h1size, 0, 360 );
		//		//_gBrush = new System.Drawing.Drawing2D.PathGradientBrush( _gpath );
		//		//_gBrush.CenterColor = this.Parent.BackColor;
		//		//_gBrush.SurroundColors = new Color[] { this.State == SymbolState.On ? Color.Red : Color.Lime };
		//		//_gBrush.WrapMode = WrapMode.TileFlipY;
		//		//pea.Graphics.FillPath( _gBrush, _gpath );
		//	}
		//	//_gpath.CloseFigure();
		//	//_gpath.AddLine( l3x1, l3y1, l3x2, l3y2 );
		//	_gpath.CloseFigure();
		//	_gpath.AddLine( l1x1, l1y1, l1x2, l1y2 );
		//	_gpath.CloseFigure();
		//	_gpath.AddLine( l2x1, l2y1, l2x2, l2y2 );

		//	if ( this._orientation == SymbolOrientation.Horizontal )
		//	{
		//		this.matrix = new Matrix();
		//		this.matrix.Rotate( 90, MatrixOrder.Prepend );
		//		pea.Graphics.Transform = this.matrix;
		//	}

		//	this.Height = ( int ) Math.Ceiling( l2y2 );
		//	this.Width = ( int ) Math.Ceiling( t1size + 1 );

		//	pea.Graphics.DrawPath( this.Pen, _gpath );
		//}

		private new void Paint( PaintEventArgs pea )
		{
			this.BackColor = Color.Black;

			System.Drawing.Drawing2D.PathGradientBrush _gBrush = null;
			System.Drawing.Drawing2D.GraphicsPath _gpath = new System.Drawing.Drawing2D.GraphicsPath();
			PointF pointA = new PointF();
			PointF pointB = new PointF();
			PointF pointC = new PointF();

			this.Width = this.SymbolSize;
			this.Height = this.SymbolSize * 3;

			//handler
			pointA.X = this.SymbolSize / 2;
			pointA.Y = 0;

			pointB.X = this.SymbolSize / 2;
			pointB.Y = this.SymbolSize;

			_gpath.AddLines( new PointF[] { pointA, pointB } );

			pointA.X = 0;
			pointA.Y = this.SymbolSize;

			pointB.X = this.SymbolSize;
			pointB.Y = this.SymbolSize;

			pointC.X = this.SymbolSize / 2;
			pointC.Y = this.SymbolSize * 2;

			_gpath.AddLines( new PointF[] { pointA, pointB, pointC, pointA } );

			pointA.X = this.SymbolSize / 2;
			pointA.Y = this.SymbolSize * 3;

			_gpath.AddLines( new PointF[] { pointC, pointA } );
			pea.Graphics.DrawPath( this.Pen, _gpath );

		}

	}
}